import java.util.*;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
class Solution {
    public List<List<Integer>> levelOrderBottom(TreeNode root) {
        List<List<Integer>> lists = new LinkedList<>();
        if (root == null) {
            return lists;
        }
        Queue<TreeNode> queue = new LinkedList<TreeNode>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            List<Integer> list = new ArrayList<Integer>();
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode node = queue.poll();
                list.add(node.val);
                TreeNode left = node.left;
                TreeNode right = node.right;
                if (left != null) {
                    queue.offer(left);
                }
                if (right != null) {
                    queue.offer(right);
                }
            }
            lists.add(0, list);

        }
        return lists;
    }
int i = 0;
    public  TreeNode creat(String s){
        TreeNode  root = null;
        if(s.charAt(i) != '#'){
            root = new TreeNode(s.charAt(i));
            i++;
            root.left = creat(s);
            root.right = creat(s);
        }
        else{
            i++;
        }

        return root;
    }
}
public class cengxu_TreeNode2 {
    public static void main(String[] args) {
        String s = new String("abc##de#g##f###");
        Solution solution = new Solution();
        TreeNode root = solution.creat(s);
       List<List<Integer>> l = solution.levelOrderBottom(root);
        System.out.println(l);
    }
}
